package com.duke.javaagent.bytebuddy02.interceptor;

import net.bytebuddy.implementation.bind.annotation.RuntimeType;

import net.bytebuddy.implementation.bind.annotation.*;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * @author gjy
 * @create 2024-12-10 10:46 AM
 */
public class StringUtilInterceptor {
    @RuntimeType
    public Object intercept(@Origin Class<?> targetClazz,
                                   @Origin Method targetMethod,
                                   @AllArguments Object[] args,
                                   @SuperCall Callable<?> zuperCall) {
        System.out.println("StringUtil Interceptor exec before，方法名称： "+targetMethod+"打印所有参数:" +args );
        long startTime = System.currentTimeMillis();
        Object call = null;
        try {
            //调用目标方法
            call = zuperCall.call();
            System.out.println("StringUtil Interceptor exec  after,执行结果： "+call);
        } catch (Exception e) {
            System.out.println("StringUtil Interceptor error，异常信息" + e);
        }finally {
            long endTime = System.currentTimeMillis();
            System.out.println("StringUtil Interceptor exec time：" + (endTime - startTime) + "ms");
        }
        return call;
    }
}
